import ServiceBase from '../base';
import {httpResultProxy} from '../proxy';
import {AddinsListProxy, AddinsProxy} from '../proxies/addins-proxy';

const ACCOUNTS = '/accounts';
const PROJECTS = '/projects';
const ADDINS = '/addins';

class AddinsService extends ServiceBase {
    getAddinsMainBar = (data) => {
        let promise = super.get({
            url: `${ACCOUNTS}/${data.accountId}${ADDINS}/search`,
            params: data.data,
        });
        return httpResultProxy(promise, AddinsListProxy);
    };
    getProjectAddinMainBar = (data) => {
        let promise = super.get({
            url: `${ACCOUNTS}/${data.accountId}${PROJECTS}/${data.projectId}${ADDINS}/search`,
            params: data.data,
        });
        return httpResultProxy(promise, AddinsListProxy);
    };
    // PUT /accounts/{accountId}/addins/{id} 根据插件Id修改插件。
    updateAddinName = (data) => {
        let promise = super.put({
            url: `${ACCOUNTS}/${data.accountId}${ADDINS}/${data.addinId}`,
            data: data.data,
        });
        return httpResultProxy(promise, AddinsProxy);
    };
    // PUT /addins/sequence 修改插件的顺序。
    updateAddinSequence = (data) => {
        let promise = super.put({
            url: `${ACCOUNTS}/${data.accountId}${ADDINS}/order`,
            data: data.data,
        });
        return httpResultProxy(promise);
    };
    // PUT /accounts/{accountId}/addins/{addinId}/state禁用/启用组织插件。
    switchAccountAddinState = (data) => {
        let promise = super.put({
            url: `${ACCOUNTS}/${data.accountId}${ADDINS}/${data.addinId}/state`,
            data: data.data,
        });
        return httpResultProxy(promise);
    };
    // PUT /accounts/{accountId}/projects/{projectId}/addins/{addinId} 修改项目插件别名。
    updateProjectAddinName = (data) => {
        let promise = super.put({
            url: `${ACCOUNTS}/${data.accountId}${PROJECTS}/${data.projectId}${ADDINS}/${data.addinId}`,
            data: data.data,
        });
        return httpResultProxy(promise, AddinsProxy);
    };
    // PUT /accounts/{accountId}/projects/{projectId}/addins/order项目插件排序。
    updateProjectAddinSequence = (data) => {
        let promise = super.put({
            url: `${ACCOUNTS}/${data.accountId}${PROJECTS}/${data.projectId}${ADDINS}/order`,
            data: data.data,
        });
        return httpResultProxy(promise);
    };
    // PUT /accounts/{accountId}/projects/{projectId}/addins/{addinId}/state禁用/启用项目插件。
    switchProjectAddinState = (data) => {
        let promise = super.put({
            url: `${ACCOUNTS}/${data.accountId}${PROJECTS}/${data.projectId}${ADDINS}/${data.addinId}/state`,
            data: data.data,
        });
        return httpResultProxy(promise);
    };
}

export {AddinsService};
